package com.example.nkj.listview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class listview extends AppCompatActivity {

    /*
    定义数组来表示listView要显示，也是我们学习哪些常用的控件
     */
    private static final String[] commonFunList = new String[]{

            "ListView控件演示",
            "ProgressBar控件演示",
            "GridView控件演示",
            "ScrollView控件演示",
            "DatePicker控件演示"
    };
    //定义listView
    private ListView listView ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_listview);

        //根据ID找到控件
        listView = (ListView) findViewById(R.id.listview);
        //添加内容
        //android.R.layout.select_dialog_singlechoice 为样式
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.select_dialog_singlechoice, commonFunList));
        listView.setItemChecked(0,true);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
            {
                setTitle("您点击了第"+position+"个项目");
            }
        });
    }
}
